package com.proscenic.oauth2;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.security.oauth2.core.AuthorizationGrantType;
import org.springframework.security.oauth2.core.ClientAuthenticationMethod;
import org.springframework.security.oauth2.server.authorization.client.JdbcRegisteredClientRepository;
import org.springframework.security.oauth2.server.authorization.client.RegisteredClient;
import org.springframework.security.oauth2.server.authorization.config.ClientSettings;
import org.springframework.security.oauth2.server.authorization.config.TokenSettings;

import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.function.Consumer;

@SpringBootApplication
public class Oauth2Application {

    public static void main(String[] args) {
        SpringApplication.run(Oauth2Application.class, args);
    }

    @Bean
    public void createClient(JdbcTemplate jdbcTemplate){
        RegisteredClient client = RegisteredClient.withId(UUID.randomUUID().toString())
                .clientId("mylife")
                .clientSecret("secret")
                //授权方法
                .clientAuthenticationMethod(ClientAuthenticationMethod.CLIENT_SECRET_BASIC)
                //授权类型
                .authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE)
                .authorizationGrantType(AuthorizationGrantType.REFRESH_TOKEN)
                //回调地址
                .redirectUri("none")
                //范围
                .scope("all")
                .tokenSettings(TokenSettings.builder().build())
                //客户端配置
                .clientSettings(ClientSettings.builder().requireAuthorizationConsent(true).build())
                .build();

    }


}
